<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>${userType==null?"用户":userType}管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnExport").click(function () {
                top.$.jBox.confirm("确认要导出${userType==null?"用户":userType}数据吗？", "系统提示", function (v, h, f) {
                    if (v == "ok") {
                        $("#searchForm").attr("action", "${ctx}/sys/user/export");
                        $("#searchForm").submit();
                    }
                }, {buttonsFocus: 1});
                top.$('.jbox-body .jbox-icon').css('top', '55px');
            });
            $("#btnImport").click(function () {
                $.jBox($("#importBox").html(), {
                    title: "导入数据", buttons: {"关闭": true},
                    bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
                });
            });
        });
        function page(n, s) {
            var flag =
            ${user.delFlag}
            if (n) $("#pageNo").val(n);
            if (s) $("#pageSize").val(s);
            $("#searchForm").attr("action", "${ctx}/sys/user/listJJR");
            if (flag == '0')
                $("#searchForm").attr("action", "${ctx}/sys/user/listJJRSHZ");
            $("#searchForm").submit();
            return false;
        }

        //清除缓存
        function clearCache(userId) {
            //服务预约列表信息
            url = "${ctx}/sys/user/clearCache/id/" + userId;
            $.ajax({
                type: "get",
                url: url,
                dataType: 'json',
                // data: parameter,
                success: function (data, textStatus) {
                    alert("同步成功");
                },
                complete: function (XMLHttpRequest, textStatus) {
                },
                error: function () {
                }
            });
        }
        ;

        //同步IM
        function regIm(userId) {
            //服务预约列表信息
            url = "${ctx}/sys/user/regIm/id/" + userId;
            $.ajax({
                type: "get",
                url: url,
                dataType: 'json',
                // data: parameter,
                success: function (data, textStatus) {
                    alert("同步成功");
                },
                complete: function (XMLHttpRequest, textStatus) {
                },
                error: function () {
                }
            });
        }
        ;

    </script>
</head>
<body>
<div id="importBox" class="hide">
    <form id="importForm" action="${ctx}/sys/user/import" method="post"
          enctype="multipart/form-data"
          class="form-search" style="padding-left:20px;text-align:center;"
          onsubmit="loading('正在导入，请稍等...');"><br/>
        <input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
        <input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
        <a href="${ctx}/sys/user/import/template">下载模板</a>
    </form>
</div>
<ul class="nav nav-tabs">
    <c:if test="${user.delFlag=='0'}">
        <li class="active"><a href="#">${userType==null?"用户":userType}列表</a></li>
    </c:if>
    <c:if test="${user.delFlag=='1'}">
        <li class="active"><a href="${ctx}/sys/user/listJJR">${userType==null?"用户":userType}列表</a>
        </li>
        <li>
            <a href="${ctx}/sys/user/${userUrl==null?"formJJR":userUrl}">${userType==null?"用户":userType}列表添加</a>
        </li>
    </c:if>
</ul>
<form:form id="searchForm" modelAttribute="user" action="${ctx}/sys/user/listJJR" method="post"
           class="breadcrumb form-search ">
    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
    <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
    <sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/>
    <ul class="ul-form">
        <li><label>企业：</label>
            <form:select path="institutionId" class="input-xlarge required ">
                <form:options items="${fns:getInstitutionList()}" itemLabel="institutionName"
                              itemValue="id" htmlEscape="false"/>
            </form:select>
        </li>
        <li><label>登录名：</label><form:input path="loginName" htmlEscape="false" maxlength="50"
                                           class="input-medium"/></li>
        <li><label>姓&nbsp;&nbsp;&nbsp;名：</label><form:input path="name" htmlEscape="false"
                                                            maxlength="50" class="input-medium"/>
        </li>
        <li><label>是否专家：</label>
            <select name="identity" class="input-medium">
                <option value="">全部</option>
                <option value="expert">是</option>
                <option value="other">否</option>
            </select>
        </li>
        <li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"
                                onclick="return page();"/>
        <li class="clearfix"></li>
    </ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <th>ID</th>
    <th class="sort-column login_name">${userType}登录名</th>
    <th class="sort-column name">${userType==null?"用户":userType}列表名称</th>
    <th>电话</th>
    <th>性别</th>
    <th>备注</th>
    <th>注册时间</th>
    <th>登录时间</th>
    <th>是否专家</th>
    <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${page.list}" var="user">
        <tr>
            <td>${user.id}</td>
            <td>${user.account}</td>
            <td>${user.name}</td>
            <td>${user.phone}</td>
            <td>${user.sex}</td>
            <td>${user.remarks}</td>
            <td>
                <fmt:formatDate value="${user.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </td>
            <td>
                <fmt:formatDate value="${user.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </td>
            <td>
                <c:choose>
                    <c:when test="${user.identity == 'expert'}">
                        是
                    </c:when>
                    <c:otherwise>否
                    </c:otherwise>
                </c:choose>
            </td>
            <td>
                <c:if test="${user.delFlag=='0'}">
                    <a href="${ctx}/sys/user/formJJRDetail?id=${user.id}&&userType=${userType==null?"用户":userType}">明细</a>
                    <a href="${ctx}/sys/user/updateUser?id=${user.id}&&userType=${user.userType}"
                       onclick="return confirmx('确认要还原该${userType==null?"用户":userType}吗？', this.href)">还原</a>
                    <a href="#" onclick="clearCache(${user.id})">清除缓存</a>
                </c:if>
                <c:if test="${user.delFlag=='1'}">
                    <a href="${ctx}/sys/user/formTrade?id=${user.id}">修改</a>
                    <a href="${ctx}/sys/user/delete?id=${user.id}&&userType=${user.userType}"
                       onclick="return confirmx('确认要删除该${userType==null?"用户":userType}吗？', this.href)">删除</a>
                    <a href="#" onclick="clearCache(${user.id})">清除缓存</a>
                    <a href="#" onclick="regIm(${user.id})">注册IM</a>
                    <c:choose>
                        <c:when test="${user.identity == 'expert'}">
                            <a href="${ctx}/sys/user/saveExpert/${user.id}"
                               onclick="return confirmx('确认${user!=null?user.name:null}取消专家吗？',this.href)">取消专家</a>
                        </c:when>
                        <c:otherwise>
                            <a href="${ctx}/sys/user/saveExpert/${user.id}"
                               onclick="return confirmx('确认${user!=null?user.name:null}要成为专家吗？',this.href)">成为专家</a>
                        </c:otherwise>
                    </c:choose>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pagination">${page}</div>
</body>
</html>